package com.ddwl.data.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.data.OperateLogBo;
import com.ddwl.data.service.OperateLogService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.data.OperateLogVo;
import com.ddwl.schema.bo.user.UserSearchBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.order.StatisticsUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author hemiaojun
 * @Date 2020/11/10 16:34
 */
@RestController
@RequestMapping("/operateLog")
@Api(tags = "操作日志")
public class OperateLogController extends BaseController {

    @Resource
    private OperateLogService operateLogService;

    @PostMapping("/queryUpdateInviteCode")
    @ApiOperation("查询修改邀请码操作记录")
    @Auth(product = BaseEnum.ProductEnum.API)
    RestVo<OperateLogVo> queryUpdateInviteCode(@RequestParam String userId){
        return RestVo.ok(operateLogService.queryUpdateInviteCode(userId));
    }

    /**
     * 获取操作日志数量
     * @param code
     * @param key
     * @param method
     * @return
     */
    @GetMapping("/countOperateLog")
    @ApiOperation("获取操作日志数量")
    @Auth(product = BaseEnum.ProductEnum.API)
    RestVo<Integer> countOperateLog(@RequestParam Integer code, @RequestParam String key, @RequestParam String method){
        return RestVo.ok(operateLogService.countOperateLog(code,key,method));
    }

    @PostMapping("/consolePage")
    @ApiOperation("后台操作记录分页")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    RestVo<PageVo<OperateLogVo>> consolePage(@RequestBody PageBo<OperateLogBo> pageBo){
        pageBo.getParam().setPk(BaseEnum.ProductEnum.CONSOLE.getName());
        return RestVo.ok(operateLogService.consolePage(pageBo));
    }

    /**
     * 活跃用户数量
     * @param bo
     * @return
     */
    @PostMapping("/activeUserCount")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo<List<StatisticsUserVo>> activeUserCount(@RequestBody UserSearchBo bo){
        List<StatisticsUserVo> list=operateLogService.queryActiveUserCount(bo);
        return RestVo.ok(list);
    }

    @PostMapping("/changeId")
    @ApiOperation("把id反转成时间戳")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo changeId(){
        operateLogService.changeId();
        return RestVo.ok();
    }

}
